package cn.wellwan.mybatis.utils;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * creator: maokai
 * on: 2018/3/6
 * description:
 */
public class MyEnumTypeHandler implements TypeHandler<Gender> {
    @Override
    public void setParameter (PreparedStatement ps , int i , Gender parameter , JdbcType jdbcType) throws SQLException {
        ps.setInt(parameter.getId(),i);
    }

    @Override
    public Gender getResult (ResultSet rs , String columnName) throws SQLException {
        int anInt = rs.getInt(columnName);
        return Gender.getGender(anInt);
    }

    @Override
    public Gender getResult (ResultSet rs , int columnIndex) throws SQLException {
        return Gender.getGender(rs.getInt(columnIndex));
    }

    @Override
    public Gender getResult (CallableStatement cs , int columnIndex) throws SQLException {
        return Gender.getGender(cs.getInt(columnIndex));
    }
}
